<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/scroll.css}">
</head>
<body>
<div class="layui-fluid">
    <nav style="margin: 10px 0; padding-bottom:5px;border-bottom: 1px dashed darkgray;">
    <span class="layui-breadcrumb">
        <a th:href="@{/admin/home}">首页</a>
        <a>系统管理</a>
        <a>
            <cite>日志管理</cite>
        </a>
    </span>
    </nav>
    <div class="layui-row">
        <div class="layui-col-md8" style="margin-bottom: 15px;">
            <a th:href="@{/admin/sys/log/export}" type="button" class="layui-btn layui-btn-sm layui-btn-warm">
                <i class="layui-icon">&#xe63c;</i>
                导出
            </a>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="page(-1)">
                <i class="layui-icon">&#xe65a;</i>
                上一页
            </button>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="page(1)">
                <i class="layui-icon">&#xe65b;</i>
                下一页
            </button>
        </div>

        <div class="layui-col-md4">

        </div>
    </div>
    <div class="layui-row">
        <p style="text-align: left;color: darkgray;">共检索到数据
            <span style="color: red;" th:text="${total}"></span>
            条,当前第
            <span style="color: red;" th:text="${current}"></span> 页 ,
            每页显示
            <select name="pageSize">
                <option th:selected="${pageSize==5}" value="5">5</option>
                <option th:selected="${pageSize==10}" value="10">10</option>
                <option th:selected="${pageSize==50}" value="50">50</option>
                <option th:selected="${pageSize==100}" value="100">100</option>
                <option th:selected="${pageSize} == ${total}" th:value="${total}">全部</option>
            </select>
            条 。
        </p>
    </div>
    <div>
        <table class="layui-table layui-table-page my-table">
            <thead>
            <tr>
                <th>用户</th>
                <th>IP地址</th>
                <th>行为</th>
                <th>级别</th>
                <th>时间</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="log,logStat : ${logList}">
                <td th:text="${log.user}"></td>
                <td th:text="${log.host}"></td>
                <td th:text="${log.action}"></td>
                <td th:if="${log.level==0}">正常</td>
                <td th:if="${log.level==1}" style="color: yellow;">警告</td>
                <td th:if="${log.level==2}" style="color: red;">高危</td>
                <td th:text="${#dates.format(log.created, 'yyyy年MM月dd日 HH:mm:ss')}"></td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="layui-row" style="margin: 15px 0;">
        <div class="layui-col-md12">
            <div class="layui-btn-group" style="text-align: right;float: right;">
                <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="page(-1)">
                    <i class="layui-icon">&#xe65a;</i>
                    上一页
                </button>
                <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="page(1)">
                    <i class="layui-icon">&#xe65b;</i>
                    下一页
                </button>
            </div>
        </div>
    </div>

</div>

<script th:src="@{/js/jquery-3.4.1.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/lay/modules/element.js}"></script>
<script th:src="@{/layui/lay/modules/table.js}"></script>

<script th:inline="javascript">
    function page(d) {
        var currentPage = 0;
        if (d === -1) {
            currentPage = [[${current}]] - 1;
            if (currentPage == 0) {
                layer.msg("已经是第一页了", {icon: 5})
                return false;
            }
        } else {
            if ([[${hasNext}]]) {
                currentPage = [[${current}]] + 1;
            } else {
                layer.msg("已经是第最后一页了", {icon: 5})
                return false
            }
        }
        location.href = "log?currentPage=" + currentPage + "&pageSize="+[[${pageSize}]];
    }
    $(function () {
        $("[name=pageSize]").change(function (e) {
            location.href = "log?currentPage=1&pageSize="+e.target.value;
        })
    })
</script>


</body>
</html>